﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System;
using Renren.Common;

namespace Renren.ServiceProviders
{
    public abstract class ServiceProvider
    {
        public static event EventHandler<ResponseErrorEventArgs> ResponseError;

        public static void NotifyResponseError(string errorCode, string errorMessage)
        {
            if (ResponseError != null)
            {
                ResponseError(null, new ResponseErrorEventArgs(errorCode, errorMessage));
            }
        }

        public ServiceProviderType Type
        {
            get;
            private set;
        }

        public string GetRequestUri(Dictionary<string, string> parameters)
        {
            var uri = ApiUriBase + "?";
            foreach (var param in GetFinalParameters(parameters))
            {
                uri += param.Key + "=" + param.Value + "&";
            }

            return uri;
        }

        public abstract bool CheckResponseResult(string result);

        protected ServiceProvider(ServiceProviderType type)
        {
            this.Type = type;
        }

        protected Dictionary<string, string> Parameters
        {
            get;
            private set;
        }

        protected abstract string ApiUriBase
        {
            get;
        }

        protected abstract Dictionary<string, string> GetFinalParameters(Dictionary<string, string> parameters);
    }
}
